package com.css.msgcenter.server.imp;

import net.sf.json.JSONObject;

import java.util.ResourceBundle;

import com.caucho.hessian.client.HessianProxyFactory;
import com.css.apps.base.dict.service.DictMan;
import com.css.msgcenter.Results;
import com.css.msgcenter.server.BizLog;
import com.css.msgcenter.server.Constants;
import com.css.msgcenter.server.IAMServlet;
import com.css.msgcenter.server.IPusher;
import com.css.msgcenter.server.MessageResult;
import com.css.msgcenter.server.model.MsgMain;
import com.css.msgcenter.server.model.MsgTask;

public class PhonePusher implements IPusher{
	private static BizLog log = new BizLog(PhonePusher.class);
	
	private static final String IMSERVER = ResourceBundle.getBundle("appconfig").getString("msgcenter.imserver");
	
	@Override
	public MessageResult send(MsgTask task, MsgMain main) {
		try {
//			发送
			final String URL = IMSERVER;
			HessianProxyFactory factory = new HessianProxyFactory();
			IAMServlet servlet = (IAMServlet) factory.create(IAMServlet.class, URL);
			int res = servlet.push(task.toJson().toString(), main.toJson().toString());
			if (res == Results.SUCCESS) {
				log.info("==Push Success: "+URL);
			} else {
				log.info("==Push Failed: "+URL);
			}
			log.info("\nphoneeeeeeeeeeeeeeeeeeeeeeee");
			JSONObject resj = new JSONObject().element("receiverId", task.getReceiverId()).element("url", URL);
			return new MessageResult(res, resj);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			JSONObject resj = new JSONObject().element("exception", e.toString());
			return new MessageResult(Results.ERROR, resj);
		}
		
		
	} 

}
